﻿using ProjScan.RecordManager;
using ProjScan.RecordManager.AssetData;
using ProjScan.ScanRule.Attr;
using ProjScan.Tools;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace ProjScan.ScanRule.ProjectAssets.Material
{
    [MaterialRuleAttr]
    internal class Mat_EqualTex : RecordRuleImp<MaterialAssetData, MaterialRecordManager>
    {
        protected override bool IsOK(MaterialAssetData assetData)
        {
            HashSet<string> hashSet = new HashSet<string>();
            MaterialProperty[] materialProperties = assetData.MaterialProperties;
            foreach (MaterialProperty materialProperty in materialProperties)
            {
                Texture textureValue = materialProperty.textureValue;
                if (textureValue != null && materialProperty.flags != MaterialProperty.PropFlags.PerRendererData)
                {
                    string gUID = ToolsHelper.GetGUID(textureValue);
                    if (hashSet.Contains(gUID))
                    {
                        return false;
                    }

                    hashSet.Add(gUID);
                }
            }

            return true;
        }
    }
}